package com.offcn.dao.impl;

import com.offcn.dao.ProductDao;
import com.offcn.domain.Product;
import com.offcn.utils.BaseDao;

import java.util.List;

public class ProductDaoImpl extends BaseDao implements ProductDao {
    @Override
    public List<Product> findPros() {
        String sql= " select * from product ";
        return findObjs(sql,Product.class);
    }

    @Override
    public int insertProduct(Product p) {
        String sql = " insert into product values(?,?,?,?,?,?) ";
        return update(sql,p.getPid(),p.getPname(),p.getMarket_price(),p.getShop_price(),p.getPdate(),p.getPdesc());
    }

    @Override
    public void delProduct(String pid) {
        String sql = " delete from product where pid=? ";
        update(sql,pid);
    }

    @Override
    public Product findProById(String pid) {
        String sql = "select * from product where pid=?";
        return findSingle(sql, Product.class, pid);
    }

    @Override
    public int findTotalCount() {
        return findCount(" select count(*) from product");
    }

    @Override
    public List<Product> findPageProduct(int index, int pageSize) {
        String sql = " select * from product limit ?,? ";
        return findObjs(sql,Product.class,index,pageSize);
    }
}
